home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / UXTRAP.H < prev    next >
C/C++ Source or Header  |  1992-04-30  |  15KB  |  454 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/uxtrap.h,v 1.13 1992/04/30 04:05:42 cph Exp $
  4.  
  5. Copyright (c) 1990-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. #ifndef SCM_UXTRAP_H
  36. #define SCM_UXTRAP_H
  37.  
  38. #include "os.h"
  39.  
  40. #ifdef hp9000s300
  41.  
  42. #include <sys/sysmacros.h>
  43. #include <machine/sendsig.h>
  44. #include <machine/reg.h>
  45.  
  46. #define HAVE_FULL_SIGCONTEXT
  47. #define PROCESSOR_NREGS            16
  48. #define FULL_SIGCONTEXT_NREGS        GPR_REGS /* Missing sp */
  49.  
  50. #define RFREE                AR5
  51. #define SIGCONTEXT            full_sigcontext
  52. #define SIGCONTEXT_SP(scp)        ((scp)->fs_context.sc_sp)
  53. #define SIGCONTEXT_PC(scp)        ((scp)->fs_context.sc_pc)
  54. #define FULL_SIGCONTEXT_RFREE(scp)    ((scp)->fs_regs[RFREE])
  55. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->fs_regs[GPR_START]))
  56.  
  57. #define INITIALIZE_UX_SIGNAL_CODES()                    \
  58. {                                    \
  59.   DECLARE_UX_SIGNAL_CODE                        \
  60.     (SIGFPE, (~ 0L), 0, "software floating point exception");        \
  61.   DECLARE_UX_SIGNAL_CODE                        \
  62.     (SIGFPE, (~ 0L), 5, "integer divide by zero");            \
  63.   DECLARE_UX_SIGNAL_CODE                        \
  64.     (SIGFPE, (1L << 15), (1L << 15), "branch/set on unordered");    \
  65.   DECLARE_UX_SIGNAL_CODE                        \
  66.     (SIGFPE, (1L << 14), (1L << 14), "signalling NAN");            \
  67.   DECLARE_UX_SIGNAL_CODE                        \
  68.     (SIGFPE, (1L << 13), (1L << 13), "operand error");            \
  69.   DECLARE_UX_SIGNAL_CODE                        \
  70.     (SIGFPE, (1L << 12), (1L << 12), "overflow");            \
  71.   DECLARE_UX_SIGNAL_CODE                        \
  72.     (SIGFPE, (1L << 11), (1L << 11), "underflow");            \
  73.   DECLARE_UX_SIGNAL_CODE                        \
  74.     (SIGFPE, (1L << 10), (1L << 10), "divide by zero");            \
  75.   DECLARE_UX_SIGNAL_CODE                        \
  76.     (SIGFPE, (1L << 9), (1L << 9), "inexact operation");        \
  77.   DECLARE_UX_SIGNAL_CODE                        \
  78.     (SIGFPE, (1L << 8), (1L << 8), "inexact decimal input");        \
  79.   DECLARE_UX_SIGNAL_CODE                        \
  80.     (SIGILL, (~ 0L), 0, "illegal instruction");                \
  81.   DECLARE_UX_SIGNAL_CODE                        \
  82.     (SIGILL, (~ 0L), 6, "check instruction");                \
  83.   DECLARE_UX_SIGNAL_CODE                        \
  84.     (SIGILL, (~ 0L), 7, "TRAPV instruction");                \
  85.   DECLARE_UX_SIGNAL_CODE                        \
  86.     (SIGILL, (~ 0L), 8, "privileged instruction");            \
  87. }
  88.  
  89. #endif /* hp9000s300 */
  90.  
  91. #ifdef hp9000s800
  92.  
  93. #include <sys/sysmacros.h>
  94.  
  95. /* See <machine/save_state.h> included by <signal.h> */
  96.  
  97. #ifndef sc_pc
  98. /* pcoq is the offset (32 bit in 64 bit virtual address space)
  99.    in the space included in the corresponding sc_pcsq.
  100.    head is the current instruction, tail is the next instruction
  101.    which is not necessarily the following instruction because
  102.    of delayed branching, etc.
  103.    Both queues need to be collected for some screw cases of
  104.    debugging and if there is ever a hope to restart the code.
  105.  */
  106. #define sc_pc                sc_pcoq_head
  107. #endif
  108.  
  109. #define ss_gr0                ss_flags    /* not really true */
  110. #define ss_rfree            ss_gr21        /* or some such */
  111. #define ss_schsp            ss_gr22
  112.  
  113. #define HAVE_FULL_SIGCONTEXT
  114. #define FULL_SIGCONTEXT_RFREE(scp)    ((scp)->sc_sl.sl_ss.ss_rfree)
  115. #define FULL_SIGCONTEXT_SCHSP(scp)    ((scp)->sc_sl.sl_ss.ss_schsp)
  116. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->sc_sl.sl_ss.ss_gr0))
  117. #define FULL_SIGCONTEXT_NREGS        32
  118. #define PROCESSOR_NREGS            32
  119.  
  120. /* The bottom 2 bits of the PC are protection bits.
  121.    They should be masked away before looking at the PC.
  122.  */
  123.  
  124. #define PC_VALUE_MASK            ((~0) << 2)
  125.  
  126. #define INITIALIZE_UX_SIGNAL_CODES()                    \
  127. {                                    \
  128.   DECLARE_UX_SIGNAL_CODE                        \
  129.     (SIGILL, (~ 0L), 8, "illegal instruction trap");            \
  130.   DECLARE_UX_SIGNAL_CODE                        \
  131.     (SIGILL, (~ 0L), 9, "break instruction trap");            \
  132.   DECLARE_UX_SIGNAL_CODE                        \
  133.     (SIGILL, (~ 0L), 10, "privileged operation trap");            \
  134.   DECLARE_UX_SIGNAL_CODE                        \
  135.     (SIGILL, (~ 0L), 11, "privileged register trap");            \
  136.   DECLARE_UX_SIGNAL_CODE                        \
  137.     (SIGFPE, (~ 0L), 12, "overflow trap");                \
  138.   DECLARE_UX_SIGNAL_CODE                        \
  139.     (SIGFPE, (~ 0L), 13, "conditional trap");                \
  140.   DECLARE_UX_SIGNAL_CODE                        \
  141.     (SIGFPE, (~ 0L), 14, "assist exception trap");            \
  142.   DECLARE_UX_SIGNAL_CODE                        \
  143.     (SIGFPE, (~ 0L), 22, "assist emulation trap");            \
  144. }
  145.  
  146. #define SPECIAL_SIGNAL_CODE_NAMES()                    \
  147. {                                    \
  148.   if ((signo == SIGFPE) && (code == 14))                \
  149.     switch ((((*scp) . sc_sl . sl_ss . ss_frexcp1) >> 26) & 0x3f)    \
  150.       {                                    \
  151.       case 0x20:                            \
  152.     name = "invalid operation";                    \
  153.     break;                                \
  154.       case 0x10:                            \
  155.     name = "divide by zero";                    \
  156.     break;                                \
  157.       case 0x08:                            \
  158.     name = "overflow";                        \
  159.     break;                                \
  160.       case 0x04:                            \
  161.       case 0x14:                            \
  162.       case 0x24:                            \
  163.       case 0x34:                            \
  164.     name = "underflow";                        \
  165.     break;                                \
  166.       case 0x02:                            \
  167.     name = "inexact";                        \
  168.     break;                                \
  169.       case 0x0a:                            \
  170.     name = "inexact and overflow";                    \
  171.     break;                                \
  172.       case 0x06:                            \
  173.       case 0x16:                            \
  174.       case 0x26:                            \
  175.       case 0x36:                            \
  176.     name = "inexact and underflow";                    \
  177.     break;                                \
  178.       }                                    \
  179. }
  180.  
  181. #endif /* hp9000s800 */
  182.  
  183. #ifdef sun3
  184.  
  185. #define HAVE_FULL_SIGCONTEXT
  186. #define PROCESSOR_NREGS            16
  187. #define FULL_SIGCONTEXT_NREGS        15        /* missing sp */
  188.  
  189. struct full_sigcontext
  190. {
  191.   struct sigcontext * fs_original;
  192.   int fs_regs[FULL_SIGCONTEXT_NREGS];
  193. };
  194.  
  195. #define RFREE                (8 + 5)        /* A5 */
  196. #define FULL_SIGCONTEXT            full_sigcontext
  197. #define FULL_SIGCONTEXT_SP(scp)        (scp->fs_original->sc_sp)
  198. #define FULL_SIGCONTEXT_PC(scp)        (scp->fs_original->sc_pc)
  199. #define FULL_SIGCONTEXT_RFREE(scp)    (scp->fs_regs[RFREE])
  200. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->fs_regs[0]))
  201.  
  202. #define DECLARE_FULL_SIGCONTEXT(name)                    \
  203.   struct FULL_SIGCONTEXT name [1]
  204.  
  205. #define INITIALIZE_FULL_SIGCONTEXT(partial, full)            \
  206. {                                    \
  207.   static void EXFUN (sun3_save_regs, (int * regs));            \
  208.   sun3_save_regs (& ((((full) [0]) . fs_regs) [0]));            \
  209.   (((full) [0]) . fs_original) = (partial);                \
  210. }
  211.  
  212. #endif /* sun3 */
  213.  
  214. #ifdef vax
  215.  
  216. #define HAVE_FULL_SIGCONTEXT
  217. #define PROCESSOR_NREGS            16
  218. #define FULL_SIGCONTEXT_NREGS        16
  219.  
  220. struct full_sigcontext
  221. {
  222.   struct sigcontext * fs_original;
  223.   int fs_regs [FULL_SIGCONTEXT_NREGS];
  224. };
  225.  
  226. #define RFREE                12        /* fp */
  227. #define FULL_SIGCONTEXT            full_sigcontext
  228. #define FULL_SIGCONTEXT_SP(scp)        ((scp)->fs_original->sc_sp)
  229. #define FULL_SIGCONTEXT_PC(scp)        ((scp)->fs_original->sc_pc)
  230. #define FULL_SIGCONTEXT_RFREE(scp)    ((scp)->fs_regs[RFREE])
  231. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->fs_regs[0]))
  232.  
  233. #define DECLARE_FULL_SIGCONTEXT(name)                    \
  234.   struct FULL_SIGCONTEXT name [1]
  235.  
  236. /* r0 has to be kludged. */
  237.  
  238. #define INITIALIZE_FULL_SIGCONTEXT(partial, full)            \
  239. {                                    \
  240.   static int EXFUN (vax_get_r0, (void));                \
  241.   static int * EXFUN (vax_save_start, (int * regs, int r0));        \
  242.   static void EXFUN                            \
  243.     (vax_save_finish, (int * fp,                    \
  244.                struct sigcontext * pscp,            \
  245.                struct full_sigcontext * scp));            \
  246.   vax_save_finish ((vax_save_start ((& ((((full) [0]) . fs_regs) [0])),    \
  247.                     (vax_get_r0 ()))),            \
  248.            (partial),                        \
  249.            (&(full)[0]));                    \
  250. }
  251.  
  252. #endif /* vax */
  253.  
  254. #ifdef mips
  255. #ifndef _SYSV4
  256.  
  257. /* Information on sigcontext structure in signal.h */
  258.  
  259. #ifndef sc_sp
  260. #define sc_sp                sc_regs[29]
  261. #endif
  262.  
  263. #define sc_rfree            sc_regs[9]
  264. #define sc_schsp            sc_regs[3]
  265.  
  266. #define HAVE_FULL_SIGCONTEXT
  267. #define FULL_SIGCONTEXT_RFREE(scp)    ((scp)->sc_rfree)
  268. #define FULL_SIGCONTEXT_SCHSP(scp)    ((scp)->sc_schsp)
  269. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->sc_regs[0]))
  270. #define FULL_SIGCONTEXT_NREGS        32
  271. #define PROCESSOR_NREGS            32
  272.  
  273. #define INITIALIZE_UX_SIGNAL_CODES()                    \
  274. {                                    \
  275.   DECLARE_UX_SIGNAL_CODE                        \
  276.     (SIGFPE, (~ 0L), FPE_INTOVF_TRAP, "integer overflow trap");        \
  277.   DECLARE_UX_SIGNAL_CODE                        \
  278.     (SIGFPE, (~ 0L), FPE_INTDIV_TRAP, "integer divide by 0 trap");    \
  279.   DECLARE_UX_SIGNAL_CODE                        \
  280.     (SIGFPE, (~ 0L), FPE_FLTOVF_TRAP, "floating-point overflow trap");    \
  281.   DECLARE_UX_SIGNAL_CODE                        \
  282.     (SIGFPE, (~ 0L), FPE_FLTDIV_TRAP, "floating-point divide by 0 trap"); \
  283.   DECLARE_UX_SIGNAL_CODE                        \
  284.     (SIGFPE, (~ 0L), FPE_FLTUND_TRAP, "floating-point underflow trap");    \
  285.   DECLARE_UX_SIGNAL_CODE                        \
  286.     (SIGFPE, (~ 0L), FPE_DECOVF_TRAP, "decimal overflow trap");        \
  287.   DECLARE_UX_SIGNAL_CODE                        \
  288.     (SIGFPE, (~ 0L), FPE_SUBRNG_TRAP, "subscript-range trap");        \
  289.   DECLARE_UX_SIGNAL_CODE                        \
  290.     (SIGFPE, (~ 0L), FPE_FLTOVF_FAULT, "floating-point overflow fault"); \
  291.   DECLARE_UX_SIGNAL_CODE                        \
  292.     (SIGFPE, (~ 0L), FPE_FLTDIV_FAULT, "floating-point divide by 0 fault"); \
  293.   DECLARE_UX_SIGNAL_CODE                        \
  294.     (SIGFPE, (~ 0L), FPE_FLTUND_FAULT, "floating-point underflow fault"); \
  295.   DECLARE_UX_SIGNAL_CODE                        \
  296.     (SIGILL, (~ 0L), ILL_PRIVIN_FAULT, "reserved instruction trap");    \
  297.   DECLARE_UX_SIGNAL_CODE                        \
  298.     (SIGILL, (~ 0L), ILL_RESOP_FAULT, "reserved operand trap");        \
  299.   DECLARE_UX_SIGNAL_CODE                        \
  300.     (SIGILL, (~ 0L), ILL_RESAD_FAULT, "reserved addressing trap");    \
  301. }
  302.  
  303. #else /* _SYSV4 */
  304.  
  305. /* Many of these definitions are not specific to the MIPS processor. */
  306.  
  307. #include <sys/siginfo.h>
  308. #include <sys/ucontext.h>
  309.  
  310. /* For Sony NEWS-OS 5.0.1 and earlier: */
  311. #if defined(sonyrisc) && !defined(_CFE)
  312. #define gregs gpregs
  313. #endif
  314.  
  315. #define SIGINFO_T siginfo_t *
  316. #define SIGINFO_VALID_P(info) ((info) != 0)
  317. #define SIGINFO_CODE(info) ((info) -> si_code)
  318.  
  319. #define SIGCONTEXT ucontext
  320. #define SIGCONTEXT_SP(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_SP])
  321. #define SIGCONTEXT_PC(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_EPC])
  322.  
  323. #define HAVE_FULL_SIGCONTEXT
  324. #define FULL_SIGCONTEXT_RFREE(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_T1])
  325. #define FULL_SIGCONTEXT_SCHSP(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_V1])
  326. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (((scp) -> uc_mcontext) . gregs)
  327. #define FULL_SIGCONTEXT_NREGS        NGREG
  328. #define PROCESSOR_NREGS            NGREG
  329.  
  330. #define INITIALIZE_UX_SIGNAL_CODES()                    \
  331. {                                    \
  332.   DECLARE_UX_SIGNAL_CODE                        \
  333.     (SIGFPE, (~ 0L), FPE_INTDIV, "integer divide by 0 trap");        \
  334.   DECLARE_UX_SIGNAL_CODE                        \
  335.     (SIGFPE, (~ 0L), FPE_INTOVF, "integer overflow trap");        \
  336.   DECLARE_UX_SIGNAL_CODE                        \
  337.     (SIGFPE, (~ 0L), FPE_FLTDIV, "floating-point divide by 0 trap");    \
  338.   DECLARE_UX_SIGNAL_CODE                        \
  339.     (SIGFPE, (~ 0L), FPE_FLTOVF, "floating-point overflow trap");    \
  340.   DECLARE_UX_SIGNAL_CODE                        \
  341.     (SIGFPE, (~ 0L), FPE_FLTUND, "floating-point underflow trap");    \
  342.   DECLARE_UX_SIGNAL_CODE                        \
  343.     (SIGFPE, (~ 0L), FPE_FLTRES, "floating-point inexact result");    \
  344.   DECLARE_UX_SIGNAL_CODE                        \
  345.     (SIGFPE, (~ 0L), FPE_FLTSUB, "subscript-range trap");        \
  346.   DECLARE_UX_SIGNAL_CODE                        \
  347.     (SIGFPE, (~ 0L), FPE_FLTINV, "invalid floating-point operation");    \
  348.   DECLARE_UX_SIGNAL_CODE                        \
  349.     (SIGILL, (~ 0L), ILL_ILLOPC, "illegal opcode trap");        \
  350.   DECLARE_UX_SIGNAL_CODE                        \
  351.     (SIGILL, (~ 0L), ILL_ILLOPN, "illegal operand trap");        \
  352.   DECLARE_UX_SIGNAL_CODE                        \
  353.     (SIGILL, (~ 0L), ILL_ILLADR, "illegal addressing mode trap");    \
  354.   DECLARE_UX_SIGNAL_CODE                        \
  355.     (SIGILL, (~ 0L), ILL_ILLTRP, "illegal trap");            \
  356.   DECLARE_UX_SIGNAL_CODE                        \
  357.     (SIGILL, (~ 0L), ILL_PRVOPC, "privileged opcode trap");        \
  358.   DECLARE_UX_SIGNAL_CODE                        \
  359.     (SIGILL, (~ 0L), ILL_PRVREG, "privileged register trap");        \
  360.   DECLARE_UX_SIGNAL_CODE                        \
  361.     (SIGILL, (~ 0L), ILL_COPROC, "co-processor trap");            \
  362.   DECLARE_UX_SIGNAL_CODE                        \
  363.     (SIGILL, (~ 0L), ILL_BADSTK, "bad stack trap");            \
  364. }
  365.  
  366. #endif /* _SYSV4 */
  367. #endif /* mips */
  368.  
  369. #ifdef i386
  370. /* The following are true for Mach (BSD 4.3 compatible).
  371.    I don't know about SCO or other versions.
  372.  */
  373.  
  374. #define HAVE_FULL_SIGCONTEXT
  375. #define PROCESSOR_NREGS            8
  376. #define FULL_SIGCONTEXT_NREGS        8
  377.  
  378. #define SIGCONTEXT            sigcontext
  379. #define SIGCONTEXT_SP(scp)        ((scp)->sc_esp)
  380. #define SIGCONTEXT_PC(scp)        ((scp)->sc_eip)
  381. #define FULL_SIGCONTEXT_RFREE(scp)    ((scp)->sc_edi)
  382. #define FULL_SIGCONTEXT_FIRST_REG(scp)    (&((scp)->sc_edi))
  383.  
  384. /* INITIALIZE_UX_SIGNAL_CODES should be defined. */
  385.  
  386. #endif /* i386 */
  387.  
  388. #ifndef SIGINFO_T
  389. #define SIGINFO_T int
  390. #define SIGINFO_VALID_P(info) (1)
  391. #define SIGINFO_CODE(info) (info)
  392. #endif
  393.  
  394. #ifndef SIGCONTEXT
  395. #define SIGCONTEXT        sigcontext
  396. #define SIGCONTEXT_SP(scp)    ((scp)->sc_sp)
  397. #define SIGCONTEXT_PC(scp)    ((scp)->sc_pc)
  398. #endif /* SIGCONTEXT */
  399.  
  400. #ifndef FULL_SIGCONTEXT
  401.  
  402. #define FULL_SIGCONTEXT SIGCONTEXT
  403. #define FULL_SIGCONTEXT_SP SIGCONTEXT_SP
  404. #define FULL_SIGCONTEXT_PC SIGCONTEXT_PC
  405.  
  406. #define DECLARE_FULL_SIGCONTEXT(name)                    \
  407.   struct FULL_SIGCONTEXT * name
  408.  
  409. #define INITIALIZE_FULL_SIGCONTEXT(partial, full)            \
  410.   ((full) = ((struct FULL_SIGCONTEXT *) (partial)))
  411.  
  412. #endif /* not FULL_SIGCONTEXT */
  413.  
  414. #ifndef FULL_SIGCONTEXT_NREGS
  415. #define FULL_SIGCONTEXT_NREGS 0
  416. #define FULL_SIGCONTEXT_FIRST_REG(scp) ((int *) 0)
  417. #endif
  418.  
  419. #ifndef PROCESSOR_NREGS
  420. #define PROCESSOR_NREGS 0
  421. #endif
  422.  
  423. #ifndef FULL_SIGCONTEXT_SCHSP
  424. #define FULL_SIGCONTEXT_SCHSP FULL_SIGCONTEXT_SP
  425. #endif
  426.  
  427. #ifndef INITIALIZE_UX_SIGNAL_CODES
  428. #define INITIALIZE_UX_SIGNAL_CODES()
  429. #endif
  430.  
  431. enum trap_state
  432. {
  433.   trap_state_trapped,
  434.   trap_state_exit,
  435.   trap_state_suspend,
  436.   trap_state_query,
  437.   trap_state_recover,
  438.   trap_state_exitting_soft,
  439.   trap_state_exitting_hard
  440. };
  441.  
  442. extern void EXFUN (initialize_trap_recovery, (char * C_sp));
  443. extern enum trap_state EXFUN (OS_set_trap_state, (enum trap_state state));
  444. extern void EXFUN
  445.   (trap_handler,
  446.    (CONST char * message,
  447.     int signo,
  448.     SIGINFO_T info,
  449.     struct FULL_SIGCONTEXT * scp));
  450. extern void EXFUN (hard_reset, (struct FULL_SIGCONTEXT * scp));
  451. extern void EXFUN (soft_reset, (void));
  452.  
  453. #endif /* SCM_UXTRAP_H */
  454.